/**
 * 
 */
package soa.security.dao.impl;

import javax.naming.ldap.LdapName;

import org.apache.commons.lang3.StringUtils;
import org.springframework.ldap.support.LdapNameBuilder;
import org.springframework.stereotype.Repository;

/**
 * @author Cre.Gu
 *
 */
@Repository
public class LdaptiveSupport {

	private String baseDn;
	private String regionRootCode;
	private String regionRootName;

	public String wrap4Spring(String dn) {
		if (StringUtils.isBlank(dn))
			return "";

		LdapName ldapName = LdapNameBuilder.newInstance(dn).build();
		return (String) ldapName.getSuffix(getBaseDnName().size()).toString();
	}

	public LdapName getBaseDnName() {
		return LdapNameBuilder.newInstance(getBaseDn()).build();
	}

	public String getBaseDn() {
		return baseDn;
	}

	public void setBaseDn(String baseDn) {
		this.baseDn = baseDn;
	}

	public String getRegionRootCode() {
		return regionRootCode;
	}

	public void setRegionRootCode(String regionRootCode) {
		this.regionRootCode = regionRootCode;
	}

	public String getRegionRootName() {
		return regionRootName;
	}

	public void setRegionRootName(String regionRootName) {
		this.regionRootName = regionRootName;
	}

}
